﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="欠款记录.aspx.cs" Inherits="syc.Sale.欠款记录" %>
<html>
<head runat="server">
    <title></title>
</head>
<body>    
    <form id="form1" runat="server">    
<script type="text/javascript" language="javascript" src="/common.js"></script>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
                SelectCommand="SELECT 0 as [ID], '全部' as [名称] union SELECT [ID], [名称] FROM [原料供货单位]">
            </asp:SqlDataSource>
        <div id="wintop" class="wintop">欠款记录</div>
        <asp:Panel ID="Panel1" runat="server" CssClass="panel">       
         <asp:Panel ID="Panel3" runat="server" CssClass="panel" GroupingText="查 询">  
               原料供货单位：
             <asp:DropDownList ID="GongHuoDanWei" runat="server" 
            DataSourceID="SqlDataSource1" DataTextField="名称" DataValueField="ID" 
                Width="110px">
        </asp:DropDownList>
                <asp:Button ID="Button_Query" runat="server" CssClass="button" 
                    OnClick="Button_Query_Click" Text="查 询" UseSubmitBehavior="False" />
            </asp:Panel>
        </asp:Panel>  
    <div class="gridframe">
        <div class="gridview">
        
            <table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolor="#e5cfab">
	            <tr>
		            <td class="grid-title">欠款记录</td>
		        </tr>
		        <tr>
		            <td class="grid-back">
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>"                         
                            SelectCommand="
                            if(@ID=0)
                            begin
                            select  ID,isnull(详细名称,名称) as 名称,欠款金额 from 原料供货单位 left join 原料欠款记录 on 原料欠款记录.供货ID=原料供货单位.ID order by 欠款金额 desc
                            end
                            else
                            begin
                            select  ID,isnull(详细名称,名称) as 名称,欠款金额 from 原料供货单位 left join 原料欠款记录 on 原料欠款记录.供货ID=原料供货单位.ID where ID=@ID order by 欠款金额 desc
                            end
                            "
                            UpdateCommand="
                              if not exists (select 供货ID from 原料欠款记录 where 供货ID=@ID)
                              begin
                              insert into 原料欠款记录(供货ID,欠款金额) values(@ID,@欠款金额)
                              end
                              else
                              begin
                                        UPDATE [原料欠款记录] 
                                        SET [欠款金额] = @欠款金额
                                        WHERE [供货ID] = @ID
                              end">                         
                            <SelectParameters>
                                  <asp:ControlParameter ControlID="GongHuoDanWei" PropertyName="SelectedValue" Type="Int32" Name="ID" />   
                            </SelectParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="欠款金额" Type="Decimal" />                             
                                <asp:Parameter Name="ID" Type="Int32" />
                            </UpdateParameters>
                        </asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
AutoGenerateColumns="False" CssClass="grid" DataKeyNames="ID" 
DataSourceID="SqlDataSource2" 
GridLines="None" ondatabound="GridView1_DataBound" 
onpageindexchanged="GridView1_PageIndexChanged" AllowSorting="True" 
UseAccessibleHeader="False" CaptionAlign="Top">
<PagerSettings Visible="False" />
<RowStyle CssClass="grid-row-normal" />
<Columns>
    <asp:TemplateField HeaderText="名称," SortExpression="名称,">
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text='<%# Bind("名称") %>'></asp:Label>
        </ItemTemplate>
        <HeaderStyle CssClass="grid-header" />
        <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="60px" />
    </asp:TemplateField>
    <asp:BoundField DataField="欠款金额" DataFormatString="{0:C}" HeaderText="期初欠款金额(元)">
        <HeaderStyle CssClass="grid-header" />
        <ItemStyle CssClass="grid"  Width="200px" HorizontalAlign="Right"/>
    </asp:BoundField>   
    <asp:TemplateField ShowHeader="False">
        <EditItemTemplate>
            <asp:Button ID="Button1" runat="server" CausesValidation="True" 
                CommandName="Update" Text="更新" CssClass="smallbutton" />
            <asp:Button ID="Button2" runat="server" CausesValidation="False" 
                CommandName="Cancel" Text="取消" CssClass="smallbutton" />
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Button ID="Button1" runat="server" CausesValidation="False" 
                CommandName="Edit" Text="编辑" CssClass="smallbutton" />            
        </ItemTemplate>
        <ItemStyle CssClass="smallbutton" />
    </asp:TemplateField>
</Columns>
</asp:GridView>
		            </td>
	            </tr>
	            <tr>
		            <td>
		                <table width="100%">
		                    <tr>
		                        <td class="pagebar">
                                    <asp:Button ID="Button_Pager_First" runat="server" Text="" ToolTip="首页" 
                                        CssClass="pageturn-first-b" onclick="Pager_Click" CommandName="--" />
                                    <asp:Button ID="Button_Pager_Prev" runat="server" Text="" ToolTip="上一页" 
                                        CssClass="pageturn-prev-b" onclick="Pager_Click" CommandName="-" />
                                    <input type="button" class="page-split" />第<asp:TextBox ID="TextBox_Pager" runat="server" CssClass="pageturn" 
                                        ontextchanged="Pager_Click"></asp:TextBox>页<input type="button" class="page-split" /><asp:Label ID="Label_Pages" runat="server"></asp:Label><input type="button" class="page-split" />
                                    
                                    <asp:Button ID="Button_Pager_Next" runat="server" Text="" ToolTip="下一页" 
                                        CssClass="pageturn-next-b" onclick="Pager_Click" CommandName="+" />
                                    <asp:Button ID="Button_Pager_Last" runat="server" Text="" ToolTip="末页" 
                                        CssClass="pageturn-last-b" onclick="Pager_Click" CommandName="++" />
                                </td>
                                <td align="right">
                                    <asp:Label ID="Label_Total" runat="server" CssClass="grid_totalrows"></asp:Label>
                                </td>
                            </tr>
                       </table>

		            </td>
	            </tr>
            </table>
            

        </div>
    </div>
    
    </form>
<script>
    var textboxs = document.getElementsByTagName("input");
    var i;
    for (i = 0; i < textboxs.length; i++) {
        if (textboxs[i].className == "textbox") {
            textboxs[i].onchange = function(e) { this.className = "textbox-changed"; };
            textboxs[i].onfocus = function(e) { this.select(); };
        }
        else if (textboxs[i].className == "pageturn") {
            textboxs[i].onfocus = function(e) { this.select(); };
        }

    }
    var rows = document.getElementsByTagName("tr");
    for (i = 0; i < rows.length; i++) {

        if (rows[i].className == "grid-row-normal") {
            rows[i].onmouseover = function() { this.className = "grid-row-bright"; };
            rows[i].onmouseout = function() { this.className = "grid-row-normal"; };
        }
    }
    var tds = document.getElementsByTagName("td");
    for (i = 0; i < tds.length; i++) {
        if (tds[i].className == "detailheader") {
            tds[i].innerHTML = tds[i].innerHTML.replace("*", "<span class=required>*</span>");
        }
    }
</script>
</body>

</html>
